package com.ruoyi.system.service.impl;

import java.beans.Transient;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SuperUserAddressMapper;
import com.ruoyi.system.domain.SuperUserAddress;
import com.ruoyi.system.service.ISuperUserAddressService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 用户地址值Service业务层处理
 *
 * @author xjf
 * @date 2025-08-14
 */
@Service
public class SuperUserAddressServiceImpl implements ISuperUserAddressService
{
    @Autowired
    private SuperUserAddressMapper superUserAddressMapper;

    /**
     * 查询用户地址值
     *
     * @param id 用户地址值主键
     * @return 用户地址值
     */
    @Override
    public SuperUserAddress selectSuperUserAddressById(Long id)
    {
        return superUserAddressMapper.selectSuperUserAddressById(id);
    }

    /**
     * 查询用户地址值列表
     *
     * @param superUserAddress 用户地址值
     * @return 用户地址值
     */
    @Override
    public List<SuperUserAddress> selectSuperUserAddressList(SuperUserAddress superUserAddress)
    {
        return superUserAddressMapper.selectSuperUserAddressList(superUserAddress);
    }

    /**
     * 新增用户地址值
     *
     * @param superUserAddress 用户地址值
     * @return 结果
     */
    @Override
    public int insertSuperUserAddress(SuperUserAddress superUserAddress)
    {
        return superUserAddressMapper.insertSuperUserAddress(superUserAddress);
    }

    /**
     * 修改用户地址值
     *
     * @param superUserAddress 用户地址值
     * @return 结果
     */
    @Override
    @Transactional
    public int updateSuperUserAddress(SuperUserAddress superUserAddress)
    {
        Long userId = superUserAddress.getUserId();
        if(superUserAddress.getIsDefault()==1){
            //先将所有地址设置为非默认
            superUserAddressMapper.updateIsDefaultByUserId(userId);
        }
        return superUserAddressMapper.updateSuperUserAddress(superUserAddress);
    }

    /**
     * 批量删除用户地址值
     *
     * @param ids 需要删除的用户地址值主键
     * @return 结果
     */
    @Override
    public int deleteSuperUserAddressByIds(Long[] ids)
    {
        return superUserAddressMapper.deleteSuperUserAddressByIds(ids);
    }

    /**
     * 删除用户地址值信息
     *
     * @param id 用户地址值主键
     * @return 结果
     */
    @Override
    public int deleteSuperUserAddressById(Long id)
    {
        return superUserAddressMapper.deleteSuperUserAddressById(id);
    }

    @Override
    public List<SuperUserAddress> selectSuperUserAddressListByUserId(Long userId) {
        return superUserAddressMapper.selectSuperUserAddressListByUserId(userId);
    }
}
